/*
 * 文件名称: TmpParseUtil.java
 * 版权信息: Copyright 2001-2012 ZheJiang Collaboration Data System Co., LTD. All right reserved.
 * ----------------------------------------------------------------------------------------------
 * 修改历史:
 * ----------------------------------------------------------------------------------------------
 * 修改原因: 新增
 * 修改人员: huangwb
 * 修改日期: 2012-3-1
 * 修改内容: 
 */
package com.huangwb.person.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Node;

import com.huangwb.person.bean.ArgInfo;
import com.huangwb.person.bean.OutputFile;


/**
 * 
 * @author <a href="mailto:huangwb@zjcds.com">huangwb</a> created on 2012-3-1
 * @since DE6.0
 */
public class TmpParseUtil {

    public static List<ArgInfo> parseXml(String filePath) throws DocumentException {
        Document doc = Dom4jUtils.getDocumentFromFile(filePath);
        
//        System.out.println(doc.asXML());
        @SuppressWarnings("unchecked")
        List<Node> nodes = doc.selectNodes("gen/obj");
//        System.out.println(nodes.size());
        ArgInfo argInfo = null;
        List<ArgInfo> argInfos = new ArrayList<ArgInfo>();
        for (Node node : nodes) {
            argInfo = initObj(node);
            argInfos.add(argInfo);
        }
        return argInfos;
    }
    
    private static ArgInfo initObj(Node node) {
        ArgInfo info = new ArgInfo();
        Element nodeObj = (Element)node;
        String className = nodeObj.attributeValue("className");
        String pck = nodeObj.attributeValue("pck");
        Map<String,String> attr = Dom4jUtils.parseNodeParam(node);
        
        String genType = attr.get("genType");
        String sqlFilePath = attr.get("sqlFilePath");
        String outputType = attr.get("outputType");
        String outPath = attr.get("outPath");
        String tableName = attr.get("tableName");

        OutputFile outputFile = new OutputFile();
        outputFile.setClassName(className);
        outputFile.setOutputType(outputType);
        outputFile.setPck(pck);
        outputFile.setProjectPath(outPath);
        
        info.setOutputInfo(outputFile);
        info.setPck(pck);
        info.setClassName(className);
        info.setSqlFilePath(sqlFilePath);
        info.setGenType(genType);
        info.setTableName(tableName);
        
        return info;
    }
    
}
